package com.luckyframe.project.jmeter.util;

import java.math.BigDecimal;

public class DoubleUtil {

    public static double round(double x, int scale, int roundingMethod) {
        try {
            return (new BigDecimal
                    (Double.toString(x))
                    .setScale(scale, roundingMethod))
                    .doubleValue();
        } catch (NumberFormatException ex) {
            if (Double.isInfinite(x)) {
                return x;
            } else {
                return Double.NaN;
            }
        }
    }


    public static double round(double x) {
       return round(x,2,1);
    }

    public static void main(String[] args) {

        double round = round(455.887116883117, 2, 1);

        System.out.println("round = " + round);

    }


}
